package com.maozzi.web.controller.rest.front;

import com.maozzi.web.auth.annotation.Login;
import com.maozzi.web.auth.model.UserInfo;
import com.maozzi.web.auth.util.SsoUtil;
import com.maozzi.api.user.UserService;
import com.maozzi.api.user.model.UserDTO;
import com.maozzi.common.util.CloneUtil;
import com.maozzi.web.model.front.UserVO;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户 controller
 *
 * @author maozi
 */
@RestController
@RequestMapping("/rest/front/user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 用户信息接口
     *
     * @return 返回
     */
    @GetMapping("/info.json")
    @Login
    public UserVO info() {
        UserInfo userInfo = SsoUtil.get();
        Long id = userInfo.getId();

        UserDTO dto = userService.getUser(id);

        return CloneUtil.to(dto, UserVO.class);
    }
}
